define(function(require, exports, module) {
    "require:nomunge,exports:nomunge,module:nomunge";

    var app = require('mokit/app');
    var user = require('../models/User');
    var LoginView = require('../views/login');
    var lang = require('mokit/language');
    var navigation = require('mokit/navigation');
    var commonUtils = require('../common/utils');
    var utils = require('mokit/utils');
    var langMgr = require('mokit/language');

    /**
     * 登陆页控制器
     */
    return app.controller.create({

        /**
         * 默认action
         */
        index: function(context) {
            var self = this;
            navigation.reset();
            //锁定竖屏
            app.lockOrientation('portrait');
            //显示主视图
            self.setView(new LoginView({
                model: user
            }));
            //清空返回处理队列
            commonUtils.backAction = [];
        },

        /**
         * 禁止锁屏
         */
        screenLockerDisabled: true,

        /**
         * 登录action
         */
        login: function(context) {
            var self = this;
            context.view.updateModel();
            user.login(function(err) {
                if (err) {
                    self.rootView.toast(context, err);
                } else {
                    //防止键盘还没有落下
                    utils.async(function() {
                        app.start('/home', 27);
                    }, 500);
                }
            });
        },

        reg: function(context) {
            var self = this;
            self.go(context, '/reg', '/login');
        }
    });

});